<template>
    <div class="reg">
        <van-nav-bar title="修改密码" left-arrow @click-left="$router.back()" />
        <div class="main">
            <svg class="icon tt-icon" aria-hidden="true">
                <use xlink:href="#icon-yonghu"></use>
            </svg>
            <van-form @submit="onSubmit" ref="regForm">

                <van-field v-model="oldPassword" type="password" name="oldPassword" placeholder="请输入老密码" :rules="[
                    { required: true },
                    {
                        validator: (e) => /^\w{6,12}$/.test(e),
                        message: '密码格式为6-12位字母或数字',
                    },
                ]">
                    <template #left-icon>
                        <svg class="icon pwd" aria-hidden="true">
                            <use xlink:href="#icon-mima"></use>
                        </svg>
                    </template>
                </van-field>


                <van-field v-model="newPassword" type="password" name="newPassword" placeholder="请输入新密码" :rules="[
                    { required: true },
                    {
                        validator: (e) => /^\w{6,12}$/.test(e),
                        message: '密码格式为6-12位字母或数字',
                    },
                ]">
                    <template #left-icon>
                        <svg class="icon pwd" aria-hidden="true">
                            <use xlink:href="#icon-mima"></use>
                        </svg>
                    </template>
                </van-field>

                <div style="margin: 16px;">
                    <van-button type="primary" native-type="submit" round block>确定修改
                    </van-button>
                    <!-- <van-button round block class="button" type="info" >提交</van-button> -->
                </div>
            </van-form>
        </div>

    </div>
</template>

<script>
import { Field, CellGroup, Button, Checkbox, CheckboxGroup, Form } from 'vant';
import { updatePwd } from '@/API/user';
import { mapState } from 'vuex';
export default {
    name: 'forget',
    data() {
        return {
            oldPassword: '',
            newPassword: '',
        }
    },
    computed: {
        ...mapState('users',['uid'])
    },
    components: {
        [Field.name]: Field,
        [CellGroup.name]: CellGroup,
        [Button.name]: Button,
        [Checkbox.name]: Checkbox,
        [CheckboxGroup.name]: CheckboxGroup,
        [Form.name]: Form,
    },
    methods: {


        onSubmit() {
            let { oldPassword, newPassword, uid } = this
            updatePwd({
                oldPassword, newPassword, uid
            }).then(res => {
                if (res.code == 0) {
                    console.log(res);
                    this.$toast(res.msg)
                    setTimeout(() => {
                        this.$router.replace('/login')
                    },);
                }else{
                    this.$toast(res.msg)
                }
            },
            )
        },
    },

}
</script>

<style lang="less" scoped>
.reg {
    width: 100vw;
    height: 100vh;
    position: relative;
    background-color: @baseColor;

    .main {

        box-sizing: border-box;
        padding: 20px;
        position: absolute;
        left: 50%;
        top: 50%;
        transform: translate(-50%, -50%);
        width: 80%;
        height: 65%;
        border-radius: 18px;
        background-color: rgba(255, 255, 255, .5);
        text-align: center;

        .tt-icon {
            font-size: 50px;
        }

        .tel {
            font-size: 24px;
        }

        .pwd {
            font-size: 24px;
        }

        .field {
            margin-top: 10.6667vw;
        }

        .button {
            margin-top: 10px;
        }

        .footer {
            width: 260px;
            padding: 10px 0;
        }

    }
}

::v-deep .van-cell {
    background-color: rgba(255, 255, 255, .0);
}

::v-deep .van-cell-group {
    background-color: rgba(255, 255, 255, .0);
}

::v-deep .van-nav-bar {
    background-color: rgba(255, 255, 255, .0);
}

::v-deep .van-hairline--bottom::after {
    border: none;
}

::v-deep .van-nav-bar .van-icon {
    color: #fff;
}

::v-deep .van-nav-bar__title {
    color: #fff;
}

::v-deep .van-checkbox__label {
    color: #fff;
}

::v-deep .van-checkbox {
    justify-content: center;
}
</style>